﻿Imports BUS
Imports DTO
Public Class FormQLBan
    Public _loaiTK As Integer = -1
    Public listban As New List(Of BanDTO)
    Public listUS As New List(Of USChiTietban)
    Public banBUS As New BanBUS()

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Public Sub LoadDSBanGUI()
        RibbonClientPanelMain.Controls.Clear()
        listBan = banBUS.LayDanhSachBanBUS()

        Dim x As Integer = 40 ' Kiểm tra toạ độ của x
        Dim y As Integer = 100 ' Kiểm tra toạ độ của y
        Dim i As Integer = 0 ' đặt tab index cho US
        Dim d As Integer = 0 ' Kiểm tra hàng ngang
        Dim _soUSTrenMotHangNgang As Integer = GetSoLuongHangNgang()

        For Each ban As BanDTO In listBan
            Dim usChiTietBan = New _0966005_0966052_QuanLyBi_a.USChiTietban()
            usChiTietBan.BorderStyle = BorderStyle.Fixed3D

            usChiTietBan.Name = "UsChiTietBan" & ban.MaBan
            usChiTietBan.Size = New System.Drawing.Size(190, 190)
            usChiTietBan.TabIndex = i
            usChiTietBan.AutoSize = True

            If (d Mod _soUSTrenMotHangNgang = 0 AndAlso d <> 0) Then
                x = 40
                y += 185 + 50
            End If

            i += 1
            d += 1

            usChiTietBan.Location = New System.Drawing.Point(x, y)

            x += 210
            If (_loaiTK = -1) Then
                usChiTietBan.Enabled = False
            End If

            Me.RibbonClientPanelMain.Controls.Add(usChiTietBan)
        Next


    End Sub
    Public Function GetSoLuongHangNgang() As Integer
        Dim _widthScreen As Integer = Screen.PrimaryScreen.Bounds.Width
        Dim d As Integer = 0
        Dim _sumWidth As Integer = 80

        While ((_sumWidth + 190 + 20) < _widthScreen)
            d += 1
            _sumWidth += 190 + 20
        End While

        Return d
    End Function

    Public Sub FormQLBan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDSBanGUI()
    End Sub

End Class